package com.act.web;

import org.apache.log4j.Logger;
import java.util.*;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.act.domain.Cost;
import com.act.dto.PagerDTO;
import com.act.dto.Response;
import com.act.service.api.ICostService;
import com.act.util.LoggerUtil;
import com.act.vo.PagerVo;

@RestController
@RequestMapping("/cost")
public class CostController{

	@Resource
	private ICostService costService;
	
	private final Logger LOGGER = Logger.getLogger(CostController.class);	
	
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Response add(Cost cost) {
    	 try {
    		 costService.add(cost);
             return Response.success();
         } catch (Exception e) {
             return Response.fail();
         }
    }
    
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Response update(Cost cost) {
    	 try {
    		 costService.update(cost);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
    }
    
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Response delete(int id) {
    	 try {
    		 costService.delete(id);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
    }
    
  @RequestMapping(value="/get",method = RequestMethod.POST)
  @ResponseBody
  public Response getAll(@RequestBody PagerDTO pagerDTO){
		try {
			PagerVo<Map> amlist=costService.getAllList(pagerDTO);

			return Response.success(amlist);
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
		}
		return Response.fail();
  }
}
